package com.shd.edanpei.wxapi;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.shd.edanpei.R;
import com.shd.edanpei.common.Constant;
import com.shd.edanpei.base.data.RxBusCode;
import com.shd.edanpei.base.rxbus.RxBus;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {

    private final int SUCCESS = 0;//成功
    private final int ERROR = -1;//错误
    private final int CANCEL = -2;//取消
    private IWXAPI api;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pay_result);

        api = WXAPIFactory.createWXAPI(this, Constant.APP_ID);
        api.handleIntent(getIntent(), this);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        api.handleIntent(intent, this);
    }

    @Override
    public void onReq(BaseReq req) {

    }

    @Override
    public void onResp(BaseResp resp) {
        if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
            if (resp.errCode == SUCCESS) {
                RxBus.get().send(RxBusCode.WECHAT_PAY_SUCCESS);
            } else if (resp.errCode == ERROR) {
                RxBus.get().send(RxBusCode.WECHAT_PAY_ERROR);
            } else if (resp.errCode == CANCEL) {

            }
            finish();
        }


        Runnable runnable = new Runnable() {
            @Override
            public void run() {

            }
        };


    }
}